/*
 * *****************************************************************************
 * Copyright (C) 2014-2024 Dennis Sheirer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 * ****************************************************************************
 */

// Generated by jextract

package io.github.dsheirer.source.tuner.sdrplay.api.v3_08;

import java.lang.foreign.Arena;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentAllocator;
import java.util.function.Consumer;

import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
import static java.lang.foreign.ValueLayout.OfInt;
import static java.lang.foreign.ValueLayout.OfShort;

/**
 * {@snippet lang=c :
 * struct {
 *     sdrplay_api_AgcControlT enable;
 *     int setPoint_dBfs;
 *     unsigned short attack_ms;
 *     unsigned short decay_ms;
 *     unsigned short decay_delay_ms;
 *     unsigned short decay_threshold_dB;
 *     int syncUpdate;
 * }
 * }
 */
public class sdrplay_api_AgcT {

    sdrplay_api_AgcT() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        sdrplay_api_h.C_INT.withName("enable"),
        sdrplay_api_h.C_INT.withName("setPoint_dBfs"),
        sdrplay_api_h.C_SHORT.withName("attack_ms"),
        sdrplay_api_h.C_SHORT.withName("decay_ms"),
        sdrplay_api_h.C_SHORT.withName("decay_delay_ms"),
        sdrplay_api_h.C_SHORT.withName("decay_threshold_dB"),
        sdrplay_api_h.C_INT.withName("syncUpdate")
    ).withName("$anon$36:9");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfInt enable$LAYOUT = (OfInt)$LAYOUT.select(groupElement("enable"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_AgcControlT enable
     * }
     */
    public static final OfInt enable$layout() {
        return enable$LAYOUT;
    }

    private static final long enable$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_AgcControlT enable
     * }
     */
    public static final long enable$offset() {
        return enable$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_AgcControlT enable
     * }
     */
    public static int enable(MemorySegment struct) {
        return struct.get(enable$LAYOUT, enable$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_AgcControlT enable
     * }
     */
    public static void enable(MemorySegment struct, int fieldValue) {
        struct.set(enable$LAYOUT, enable$OFFSET, fieldValue);
    }

    private static final OfInt setPoint_dBfs$LAYOUT = (OfInt)$LAYOUT.select(groupElement("setPoint_dBfs"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * int setPoint_dBfs
     * }
     */
    public static final OfInt setPoint_dBfs$layout() {
        return setPoint_dBfs$LAYOUT;
    }

    private static final long setPoint_dBfs$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * int setPoint_dBfs
     * }
     */
    public static final long setPoint_dBfs$offset() {
        return setPoint_dBfs$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * int setPoint_dBfs
     * }
     */
    public static int setPoint_dBfs(MemorySegment struct) {
        return struct.get(setPoint_dBfs$LAYOUT, setPoint_dBfs$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * int setPoint_dBfs
     * }
     */
    public static void setPoint_dBfs(MemorySegment struct, int fieldValue) {
        struct.set(setPoint_dBfs$LAYOUT, setPoint_dBfs$OFFSET, fieldValue);
    }

    private static final OfShort attack_ms$LAYOUT = (OfShort)$LAYOUT.select(groupElement("attack_ms"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned short attack_ms
     * }
     */
    public static final OfShort attack_ms$layout() {
        return attack_ms$LAYOUT;
    }

    private static final long attack_ms$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned short attack_ms
     * }
     */
    public static final long attack_ms$offset() {
        return attack_ms$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned short attack_ms
     * }
     */
    public static short attack_ms(MemorySegment struct) {
        return struct.get(attack_ms$LAYOUT, attack_ms$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned short attack_ms
     * }
     */
    public static void attack_ms(MemorySegment struct, short fieldValue) {
        struct.set(attack_ms$LAYOUT, attack_ms$OFFSET, fieldValue);
    }

    private static final OfShort decay_ms$LAYOUT = (OfShort)$LAYOUT.select(groupElement("decay_ms"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned short decay_ms
     * }
     */
    public static final OfShort decay_ms$layout() {
        return decay_ms$LAYOUT;
    }

    private static final long decay_ms$OFFSET = 10;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned short decay_ms
     * }
     */
    public static final long decay_ms$offset() {
        return decay_ms$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned short decay_ms
     * }
     */
    public static short decay_ms(MemorySegment struct) {
        return struct.get(decay_ms$LAYOUT, decay_ms$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned short decay_ms
     * }
     */
    public static void decay_ms(MemorySegment struct, short fieldValue) {
        struct.set(decay_ms$LAYOUT, decay_ms$OFFSET, fieldValue);
    }

    private static final OfShort decay_delay_ms$LAYOUT = (OfShort)$LAYOUT.select(groupElement("decay_delay_ms"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned short decay_delay_ms
     * }
     */
    public static final OfShort decay_delay_ms$layout() {
        return decay_delay_ms$LAYOUT;
    }

    private static final long decay_delay_ms$OFFSET = 12;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned short decay_delay_ms
     * }
     */
    public static final long decay_delay_ms$offset() {
        return decay_delay_ms$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned short decay_delay_ms
     * }
     */
    public static short decay_delay_ms(MemorySegment struct) {
        return struct.get(decay_delay_ms$LAYOUT, decay_delay_ms$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned short decay_delay_ms
     * }
     */
    public static void decay_delay_ms(MemorySegment struct, short fieldValue) {
        struct.set(decay_delay_ms$LAYOUT, decay_delay_ms$OFFSET, fieldValue);
    }

    private static final OfShort decay_threshold_dB$LAYOUT = (OfShort)$LAYOUT.select(groupElement("decay_threshold_dB"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned short decay_threshold_dB
     * }
     */
    public static final OfShort decay_threshold_dB$layout() {
        return decay_threshold_dB$LAYOUT;
    }

    private static final long decay_threshold_dB$OFFSET = 14;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned short decay_threshold_dB
     * }
     */
    public static final long decay_threshold_dB$offset() {
        return decay_threshold_dB$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned short decay_threshold_dB
     * }
     */
    public static short decay_threshold_dB(MemorySegment struct) {
        return struct.get(decay_threshold_dB$LAYOUT, decay_threshold_dB$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned short decay_threshold_dB
     * }
     */
    public static void decay_threshold_dB(MemorySegment struct, short fieldValue) {
        struct.set(decay_threshold_dB$LAYOUT, decay_threshold_dB$OFFSET, fieldValue);
    }

    private static final OfInt syncUpdate$LAYOUT = (OfInt)$LAYOUT.select(groupElement("syncUpdate"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * int syncUpdate
     * }
     */
    public static final OfInt syncUpdate$layout() {
        return syncUpdate$LAYOUT;
    }

    private static final long syncUpdate$OFFSET = 16;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * int syncUpdate
     * }
     */
    public static final long syncUpdate$offset() {
        return syncUpdate$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * int syncUpdate
     * }
     */
    public static int syncUpdate(MemorySegment struct) {
        return struct.get(syncUpdate$LAYOUT, syncUpdate$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * int syncUpdate
     * }
     */
    public static void syncUpdate(MemorySegment struct, int fieldValue) {
        struct.set(syncUpdate$LAYOUT, syncUpdate$OFFSET, fieldValue);
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}

